<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-row>

          <a-form-item label="资产处置" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-dict-select-tag type="list" v-decorator="['assetDisposal', validatorRules.assetDisposal]"
                               :trigger-change="true" dictCode="asset_disposal"  placeholder="请选择处置类别"/>
          </a-form-item>

          <a-form-item label="处置日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date v-decorator="['assetDisposalDate', validatorRules.assetDisposalDate]"
                    :trigger-change="true" style="width: 100%"/>
          </a-form-item>

          <a-form-item label="处置情况说明" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-textarea v-decorator="['assetDisposalDescription', validatorRules.assetDisposalDescription]" rows="4" placeholder="请输入处置情况说明"></a-textarea>
          </a-form-item>

        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'
  import { assetDisposal } from '@/api/asset'

  export default {
    name: 'AssetInfoDisposalModal',
    components: {
      JDate,
      JUpload,
      JDictSelectTag
    },
    data () {
      return {
        form: this.$form.createForm(this),
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 }
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 }
        },
        width: 700,
        disableSubmit: false,
        confirmLoading: false,
        visible: false,
        title: "",
        model: {},
        validatorRules: {
          assetDisposal: {
            rules: [
              { required: true, message: '请选择处置类别!' }
            ]
          },
        },
      }
    },
    methods: {
      show (record) {
        this.confirmLoading = false
        this.title = "资产处置"
        this.form.resetFields()
        this.model = Object.assign({}, record)
        this.visible = true
        // this.$nextTick(() => {
        //   this.form.setFieldsValue(pick(this.model,'payablesNo','leaseContractId','assetId','customerId','totalMoney','payStatus','paymentType','paymentDate','paymentBy','paymentRemark','remark','updateBy','updateTime','createBy','createTime'))
        // })
      },
      handleOk () {
        const that = this
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true
            let formData = Object.assign(this.model, values);
            assetDisposal(formData).then((res) => {
              if (res.success) {
                this.$message.success(res.message)
                this.$emit('ok');
                this.close()
              } else {
                this.$message.warning(res.message)
              }
            }).finally(() => {
              this.confirmLoading = false
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.$emit('close')
        this.visible = false
      },
    },
  }
</script>

<style scoped>
</style>